﻿using System;
using System.Diagnostics;
using TI_BLE_HCI_ClientLib.HCIBaseEntities;
using TI_BLE_HCI_ClientLib.HCIEvents;
using Utilities;

namespace TI_BLE_HCI_ClientLib.HCIParsers
{
    public static partial class HCIEventParser
    {
        private static HCIEvent parseHCI_LE_ExtEvent_GAP_Device_Init_Done(byte parsLen, byte[] buffer)
        {
            if (parsLen != 44) throw new ArgumentException("parseHCI_LE_ExtEvent_GAP_DeviceInitDone Parameters Length != 44");
            byte bufIdx = 4;

            HCIVendorSpecificEventHostErrorCode status = (HCIVendorSpecificEventHostErrorCode)parseByteParameter(buffer, ref bufIdx);
            byte[] devAddr = parseBufferParameter(6, buffer, ref bufIdx);
            ushort dataPktLen = parseWordParameter(buffer, ref bufIdx);
            byte numDataPkt = parseByteParameter(buffer, ref bufIdx);
            byte[] irk = parseBufferParameter(16, buffer, ref bufIdx);
            byte[] csrk = parseBufferParameter(16, buffer, ref bufIdx);

            var hciEvent = new HCIEvent_GAP_Device_Init_Done(status, devAddr, dataPktLen, numDataPkt, irk, csrk);

            return hciEvent;
        }
    }
}
